
boolean locked = false;

/* 
***** RMGUIBase 
*/
class RMGUIBase
{
  RMGUIBase owner;
  
  void setOwner( RMGUIBase o)
  {
    owner = o;
  };
  
  RMGUIBase getOwner()
  {
    return owner;
  };

  boolean mouseEvent( int mX, int mY)
  {
    /* result is true if Event is Consumed */
    return false;
  };
};

/*
***** RMGUIBaseContainer
*/
class RMGUIBaseContainer extends RMGUIBase
{
  ArrayList olist;
  
  RMGUIBaseContainer()
  {
    olist = new ArrayList();
  };
  
  void addObj( RMGUIBase o)
  {
    olist.add( o);
    o.setOwner( this);
  };
  
  void removeObj( RMGUIBase o)
  {
    int index = olist.indexOf( o);
    if( index > -1){
      olist.remove( o);
    };
  };
  
  
  
};
/*
***** Button *****
*/
class Button extends RMGUIBase
{
  int x, y;
  int size;
  color basecolor, highlightcolor;
  color currentcolor;
  boolean over = false;
  boolean pressed = false;   

  void update() 
  {
    if(over()) {
      currentcolor = highlightcolor;
    } 
    else {
      currentcolor = basecolor;
    }
  }

  boolean pressed() 
  {
    if(over) {
      locked = true;
      return true;
    } 
    else {
      locked = false;
      return false;
    }    
  }

  boolean over() 
  { 
    return true; 
  }

  boolean overRect(int x, int y, int width, int height) 
  {
    if (mouseX >= x && mouseX <= x+width && 
      mouseY >= y && mouseY <= y+height) {
      return true;
    } 
    else {
      return false;
    }
  }

  boolean overCircle(int x, int y, int diameter) 
  {
    float disX = x - mouseX;
    float disY = y - mouseY;
    if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
      return true;
    } 
    else {
      return false;
    }
  }

}

/*
***** CircleButton *****
*/
class CircleButton extends Button
{ 
  CircleButton(int ix, int iy, int isize, color icolor, color ihighlight) 
  {
    x = ix;
    y = iy;
    size = isize;
    basecolor = icolor;
    highlightcolor = ihighlight;
    currentcolor = basecolor;
  }

  boolean over() 
  {
    if( overCircle(x, y, size) ) {
      over = true;
      return true;
    } 
    else {
      over = false;
      return false;
    }
  }

  void display() 
  {
    stroke(255);
    fill(currentcolor);
    ellipse(x, y, size, size);
  }
}

/*
***** RectButton *****
*/
class RectButton extends Button
{
  RectButton(int ix, int iy, int isize, color icolor, color ihighlight) 
  {
    x = ix;
    y = iy;
    size = isize;
    basecolor = icolor;
    highlightcolor = ihighlight;
    currentcolor = basecolor;
  }

  boolean over() 
  {
    if( overRect(x, y, size, size) ) {
      over = true;
      return true;
    } 
    else {
      over = false;
      return false;
    }
  }

  void display() 
  {
    stroke(255);
    fill(currentcolor);
    rect(x, y, size, size);
  }
}

/*
***** RMGUI *****
*/
class RMGUI extends RMGUIBase
{
    
};
